package com.ld.collegetask;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;

import com.google.gson.Gson;
import com.ld.collegetask.beans.AlipayBriefBean;
import com.ld.collegetask.databinding.ActivityAlipayBinding;

/**
 * Created by yilan on 18/2/26.
 */

public class AlipayActivity extends BaseActivity {
    private ActivityAlipayBinding binding;
    private String resultStatus;
    private String result;
    private String memo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_alipay);
        resultStatus = getIntent().getStringExtra("resultStatus");
        result = getIntent().getStringExtra("result");
        memo = getIntent().getStringExtra("memo");
        Gson gson = new Gson();
        switch (resultStatus) {
            case "9000"://订单支付成功
                binding.text.setText("充值成功");
                AlipayBriefBean alipayBriefBean = gson.fromJson(result, AlipayBriefBean.class);
                    binding.money.setText(alipayBriefBean.getAlipay_trade_app_pay_response().getTotal_amount());
                break;
            case "8000"://正在处理中，支付结果未知（有可能已经支付成功），请查询商户订单列表中订单的支付状态
                binding.text.setText("充值失败");
                binding.money.setVisibility(View.GONE);
                break;
            case "4000"://订单支付失败
                binding.text.setText("充值失败");
                binding.money.setVisibility(View.GONE);
                break;
            case "5000"://重复请求
                binding.text.setText("充值失败");
                binding.money.setVisibility(View.GONE);
                break;
            case "6001"://用户中途取消
                finish();
                break;
            case "6002"://网络连接出错
                binding.text.setText("网络连接出错");
                binding.money.setVisibility(View.GONE);
                break;
            case "6004"://支付结果未知（有可能已经支付成功），请查询商户订单列表中订单的支付状态
                binding.text.setText("充值失败");
                binding.money.setVisibility(View.GONE);
                break;
            default://其它支付错误
                binding.text.setText("充值失败");
                binding.money.setVisibility(View.GONE);
                break;
        }

        findView();
    }

    public void findView() {
        binding.buttons.setOnClickListener(this);
    }

    @Override
    public void loading() {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.buttons:
                finish();
                break;
        }
    }
}
